package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysLoginLogMapper;
import com.atguigu.spzx.manager.entity.SysLoginLog;
import com.atguigu.spzx.manager.service.LoginLogService;
import com.atguigu.spzx.manager.service.SysLoginLogService;
import com.atguigu.spzx.manager.vo.sysLoginLog.SysLoginLogQueryReqVo;
import com.atguigu.spzx.manager.vo.sysLoginLog.SysLoginLogQueryRespVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * LoginLogServiceImpl
 * </p>
 *
 * @author flyduck
 * @since 2023/10/26
 */
@Service
public class SysLoginLogServiceImpl implements SysLoginLogService,LoginLogService {

    @Autowired
    private SysLoginLogMapper sysLoginLogMapper;


    /**
     * 保存登录日志
     *
     * @param username 登录用户名
     * @param status   登录状态
     * @param ipaddr   登录IP地址
     * @param message  登录消息
     */
    @Override
    public void recordLoginLog(String username, Integer status, String ipaddr, String message) {
        SysLoginLog sysLoginLog = new SysLoginLog();
        sysLoginLog.setUsername(username);
        sysLoginLog.setIpaddr(ipaddr);
        sysLoginLog.setStatus(status);
        sysLoginLog.setMsg(message);
        sysLoginLog.setAccessTime(new Date());
        sysLoginLogMapper.insert(sysLoginLog);
    }

    /**
     * 根据查询条件获取登录日志的分页列表
     *
     * @param pageParam 分页参数
     * @param reqVo     查询条件
     * @return 包含登录日志的分页结果
     */
    @Override
    public Page<SysLoginLogQueryRespVo> getLoginLogPageByQuery(Page<SysLoginLog> pageParam, SysLoginLogQueryReqVo reqVo) {
        return sysLoginLogMapper.getLoginLogPageByQuery(pageParam,reqVo);
    }
}
